﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.RoleCommand;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [AllowAnonymous]
    public class RoleController : ControllerBase
    {
        private readonly IMediator _mediator;

        public RoleController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PageOutput<Role>>> GetRoles(RoleInput? input)
        {
            var command = new GetRolesCommand(input);
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddRole(AddRoleInput input)
        {
            var command = new AddRoleCommand(input);
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DeleteRole(DeleteRoleCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取角色下拉框接口
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Results<List<RoleSelectOutput>>> GetRolesSelect()
        {
            var command = new RoleSelectCommand();
            return await _mediator.Send(command);
        }
    }
}
